<template>
	<div class="w-100">
		<div class="tabs-content" v-if="!showResult">
			<el-scrollbar max-height="80vh">
				<BaseInfo ref="formRef" :key="reloadForm" @submit="onChange"></BaseInfo>
			</el-scrollbar>
			<div class="fc">
				<el-button class="ap-btn" type="primary" @click="handleSubmit('submit')"> 保存 </el-button>
			</div>
		</div>
		<DataGather
			v-else
			:name="nowRowData.professorName"
			changeType="养老专家"
			:dataType="7"
			@backNext="handleBack('next')"
			@back="handleBack"
			@init="getInitMod"
		></DataGather>
	</div>
</template>

<script setup lang="ts">
import { getAreaObj } from '@/utils/util'
import apiMod from '@/apiMod'
import BaseInfo from './BaseInfo/index.vue'
import DataGather from '@/views/datacenter/components/DataGather/change/index.vue'
import { useCommonStore } from '@/stores/common'
const {setLoading} = useCommonStore()

type Props = {
	nowRowData?: any
}
const props = withDefaults(defineProps<Props>(), {})
const emit = defineEmits(['refresh'])
let nowData:any = ref({})
provide('nowRowData', nowData)
const reloadForm = ref(0)
const formRef = ref(null)
const showResult = ref(false)
const getInitMod = () => {
	showResult.value = false
}
const onChange = (data) => {
	showResult.value = true
}
const handleSubmit = (type) => {
	formRef.value!.onSave()
}
const handleBack = (type?: string) => {
	showResult.value = false
	if (type) emit('refresh')
}

const getInitData = () => {
  setLoading()
	apiMod.view_dpProfessor_view(props.nowRowData.id).then((res) => {
		const area: any = getAreaObj(res.data, '', 'set')
		nowData.value = {
			...(res.data || props.nowRowData),
			areasName: area.names,
			areas: area.areaIds,
		}
		reloadForm.value = Math.random()
    setLoading()
	})
}
onMounted(() => {
	getInitData()
})
</script>

<style scoped lang="scss"></style>
